﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Empires.CRL.DataContract;
using System.Web;
using Empires.RAL.Access;
using Empires.RAL.Pump;

namespace Empires.BLL.ServerProvider
{
    public static class RoleCheckProvider
    {
        public static bool CheckUserStatus(string username, Func<int, bool> compare)
        {
            if (String.IsNullOrEmpty(username))
            {
                return false;
            }
            Empires.RAL.Access.IAppUserAccess access = new Empires.RAL.Pump.AppUserDataPump();
            int status = access.GetUserStatus(username);
            return compare.Invoke(status);
            
        }

        public static void SetAuthInfo(ref List<DefaultDataPack> pack,string copname)
        {
            //如果已经登录
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                string username = HttpContext.Current.User.Identity.Name;
                var result = GetAuthInfo(copname, username);
                if (result.Any())
                {
                    pack = pack.Select(c =>
                    {
                        c.GROUP = result[0].GROUP;
                        c.SUBGROUP = result[0].SUBGROUP;
                        return c;
                    }).ToList();
                }
            }
        }

        public static List<DefaultDataPack> GetAuthInfo(string copname, string username)
        {
            ICompanyBaseAccess access = new CompanyBaseDataPump();
            var result = access.GetCompanyMemberShip(copname, username);
            return result;
        }
      

    }
}
